﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using Excel;
using System.Data;

public class BuildExcel
{
    /*
    static Read_xlsx read_Xlsx;

    [MenuItem("ExcelBuidl/build")]
    static void BuidlExcelData()
    {
        BuidlWin();
    }

    static void BuidlWin()
    {
        //  //6.创建窗口实体
        // BuildExcelView win = (BuildExcelView)EditorWindow.GetWindow(typeof(BuildExcelView));
        // win.titleContent = new GUIContent("Excel资源包管理");
        // //7.显示窗口实体
        // win.Show();

        tempMethod();
    }

    static void tempMethod()
    {
        BuildExcel.read_Xlsx = new Read_xlsx("Rabbit");
        EditorUtility.DisplayProgressBar("编辑器Excel进度", "正在打编辑器资源包...", 0);
        CreatXlsxAssets();
    }

    static List<RabbitLevel> SelectRabbitLevelTable()
    {
        List<RabbitLevel> levelsArr = new List<RabbitLevel>();
        DataRowCollection collect = BuildExcel.read_Xlsx.getXlsxDic["level"];
        for (int i = 2; i < collect.Count; i++)
        {
            if (collect[i][1].ToString() == "") continue;
            RabbitLevel menu = new RabbitLevel
            {
                id = int.Parse(collect[i][0].ToString()),
                model = int.Parse(collect[i][1].ToString()),
                high = float.Parse(collect[i][2].ToString()),
                clazz = float.Parse(collect[i][3].ToString()),
                subjectType = (collect[i][4].ToString()),
                balloon_type = collect[i][5].ToString(),
                gap = collect[i][6].ToString(),
                speed = float.Parse(collect[i][7].ToString()),
                flyHigh = (collect[i][8].ToString()),
            };
            levelsArr.Add(menu);
        }
        return levelsArr;
    }

    static List<RabbitMode> SelectRabbitModeTable()
    {
        List<RabbitMode> levelsArr = new List<RabbitMode>();
        DataRowCollection collect = BuildExcel.read_Xlsx.getXlsxDic["mode"];
        for (int i = 2; i < collect.Count; i++)
        {
            if (collect[i][1].ToString() == "") continue;
            RabbitMode menu = new RabbitMode
            {
                id = int.Parse(collect[i][0].ToString()),
                mode = collect[i][1].ToString(),
                cost = int.Parse(collect[i][2].ToString()),
                mode_tetx = (collect[i][3].ToString()),
                hp = int.Parse(collect[i][4].ToString())
            };
            levelsArr.Add(menu);
        }
        return levelsArr;
    }

    static List<RabbitQuestion> SelectRabbitQuestionTable()
    {
        List<RabbitQuestion> levelsArr = new List<RabbitQuestion>();
        DataRowCollection collect = BuildExcel.read_Xlsx.getXlsxDic["question"];
        for (int i = 2; i < collect.Count; i++)
        {
            if (collect[i][1].ToString() == "") continue;
            RabbitQuestion menu = new RabbitQuestion
            {
                id = int.Parse(collect[i][0].ToString()),
                difficulty = int.Parse(collect[i][1].ToString()),
                sbuject = (collect[i][2].ToString()),
                text = (collect[i][3].ToString()),
                right_answer = (collect[i][4].ToString()),
                wrong_answer_1 = (collect[i][5].ToString()),
                wrong_answer_2 = (collect[i][6].ToString()),
                wrong_answer_3 = (collect[i][7].ToString()),
                wrong_answer_4 = (collect[i][8].ToString()),
                wrong_answer_5 = (collect[i][9].ToString()),
                wrong_answer_6 = (collect[i][10].ToString()),
                helpText = (collect[i][11].ToString()),
            };
            levelsArr.Add(menu);
        }
        return levelsArr;
    }


    static List<RabbitRanking> SelectRabbitRankingTable()
    {
        List<RabbitRanking> levelsArr = new List<RabbitRanking>();
        DataRowCollection collect = BuildExcel.read_Xlsx.getXlsxDic["ranking"];
        for (int i = 2; i < collect.Count; i++)
        {
            if (collect[i][1].ToString() == "") continue;
            RabbitRanking menu = new RabbitRanking
            {
                id = int.Parse(collect[i][0].ToString()),
                point_min = float.Parse(collect[i][1].ToString()),
                point_max = int.Parse(collect[i][2].ToString()),
                rank_min = int.Parse(collect[i][3].ToString()),
                rank_max = int.Parse(collect[i][4].ToString()),
                text = (collect[i][5].ToString()),
            };
            levelsArr.Add(menu);
        }
        return levelsArr;
    }

    static List<RabbitShop> SelectRabbitShopTable()
    {
        List<RabbitShop> levelsArr = new List<RabbitShop>();
        DataRowCollection collect = BuildExcel.read_Xlsx.getXlsxDic["shop"];
        for (int i = 2; i < collect.Count; i++)
        {
            if (collect[i][1].ToString() == "") continue;
            RabbitShop menu = new RabbitShop
            {
                id = int.Parse(collect[i][0].ToString()),
                desc = collect[i][1].ToString(),
                cost = int.Parse(collect[i][2].ToString()),
                num = int.Parse(collect[i][3].ToString()),
                title = (collect[i][4].ToString()),
                pic = (collect[i][5].ToString()),
                order = int.Parse(collect[i][6].ToString()),
            };
            levelsArr.Add(menu);
        }
        return levelsArr;
    }

    static List<RabbitInfot> SelectRabbitInfoTable()
    {
        List<RabbitInfot> levelsArr = new List<RabbitInfot>();
        DataRowCollection collect = BuildExcel.read_Xlsx.getXlsxDic["info"];
        for (int i = 2; i < collect.Count; i++)
        {
            if (collect[i][1].ToString() == "") continue;
            RabbitInfot menu = new RabbitInfot
            {
                key = (collect[i][0].ToString()),
                value = (collect[i][1].ToString()),
                desc = collect[i][2].ToString(),
            };
            levelsArr.Add(menu);
        }
        return levelsArr;
    }

    static List<GuardTime> SelectGuardTable()
    {
        List<GuardTime> levelsArr = new List<GuardTime>();
        DataRowCollection collect = BuildExcel.read_Xlsx.getXlsxDic["guard"];
        for (int i = 2; i < collect.Count; i++)
        {
            if (collect[i][1].ToString() == "") continue;
            GuardTime menu = new GuardTime
            {
                id = int.Parse((collect[i][0].ToString())),
                sp = (collect[i][1].ToString()),
                play_time = int.Parse((collect[i][2].ToString())),
                guard_time = int.Parse((collect[i][3].ToString())),
                tips = (collect[i][4].ToString()),
                desc = (collect[i][5].ToString())
            };
            levelsArr.Add(menu);
        }
        return levelsArr;
    }



    static void CreatXlsxAssets()
    {
        string path = "Assets/Bundle/RabbitRes/xlsx/";
        //查询excel表中数据，赋值给asset文件
        BookHolderRabbitLevel bookHolderRabbitLevel = ScriptableObject.CreateInstance<BookHolderRabbitLevel>();
        bookHolderRabbitLevel.rabbitLevel = SelectRabbitLevelTable();
        BookHolderRabbitMode bookHolderRabbitMode = ScriptableObject.CreateInstance<BookHolderRabbitMode>();
        bookHolderRabbitMode.rabbitMode = SelectRabbitModeTable();
        BookHolderRabbitQuestion bookHolderRabbitQuestion = ScriptableObject.CreateInstance<BookHolderRabbitQuestion>();
        bookHolderRabbitQuestion.rabbitQuestion = SelectRabbitQuestionTable();
        BookHolderRabbitRanking bookHolderRabbitRanking = ScriptableObject.CreateInstance<BookHolderRabbitRanking>();
        bookHolderRabbitRanking.rabbitRanking = SelectRabbitRankingTable();
        BookHolderRabbitShop bookHolderRabbitShop = ScriptableObject.CreateInstance<BookHolderRabbitShop>();
        bookHolderRabbitShop.rabbitShop = SelectRabbitShopTable();
        BookHolderRabbitInfo bookHolderRabbitInfo = ScriptableObject.CreateInstance<BookHolderRabbitInfo>();
        bookHolderRabbitInfo.rabbitInfots = SelectRabbitInfoTable();
        BookHolderGuard guardInfo = ScriptableObject.CreateInstance<BookHolderGuard>();
        guardInfo.guard = SelectGuardTable();

        EditorUtility.DisplayProgressBar("编辑器Excel进度", "正在打编辑器资源包...", 0.5f);

        InstanceXlsx(bookHolderRabbitLevel, path + "level.asset");
        InstanceXlsx(bookHolderRabbitMode, path + "mode.asset");
        InstanceXlsx(bookHolderRabbitQuestion, path + "question.asset");
        InstanceXlsx(bookHolderRabbitRanking, path + "ranking.asset");
        InstanceXlsx(bookHolderRabbitShop, path + "shop.asset");
        InstanceXlsx(bookHolderRabbitInfo, path + "info.asset");
        InstanceXlsx(guardInfo, path + "guard.asset");

        EditorUtility.DisplayProgressBar("编辑器Excel进度", "正在打编辑器资源包...", 1);

        EditorUtility.ClearProgressBar();
        AssetDatabase.Refresh();
        EditorUtility.DisplayDialog("提示", "Excel数据创建成功", "确定");
    }

    static void InstanceXlsx(ScriptableObject obj, string path)
    {
        AssetDatabase.CreateAsset(obj, path);
    }
    */
}



public class BuildExcelView : EditorWindow
{
    void OnGUI()
    {
    }
}
